package sdk.webview.fmc.com.fmcsdk.h5;

import android.content.Context;
import android.util.Log;
import android.webkit.JavascriptInterface;

import sdk.webview.fmc.com.fmcsdk.util.KLog;

/**
 * H5与JS交互类
 * Created by ydm on 2017/6/16.
 */

public class JsInterface {

    private final Context context;

    private HtmlInterface htmlInterface;

    public JsInterface(Context context, HtmlInterface htmlInterface) {
        this.context = context;
        this.htmlInterface = htmlInterface;
    }

    /**
     * 拍照功能
     *
     * @param type            拍照后上传图片的方式
     * @param max             拍照的最大数量
     * @param ownerObject     H5使用的参数
     * @param ownerType       图片的类型
     * @param ownerId         H5使用的参数
     * @param takePicCallback 拍照函数回调
     */
    @JavascriptInterface
    public void takePhoto(String type, String max, String ownerObject, String ownerType, String ownerId, String takePicCallback) {
        KLog.e("37");
        htmlInterface.takePhoto(type, max, ownerObject, ownerType, ownerId, takePicCallback);
    }

    /**
     * 拍照功能
     *
     * @param type                 拍照后上传图片的方式
     * @param max                  拍照的最大数量
     * @param ownerObject          H5使用的参数
     * @param ownerType            图片的类型
     * @param ownerId              H5使用的参数
     * @param takePicCallback      拍照函数回调
     * @param offlineIsUploadImage 离线状态是否需要上传图片
     */
    @JavascriptInterface
    public void takePhoto(String type, String max, String ownerObject, String ownerType, String ownerId, String takePicCallback, String offlineIsUploadImage) {
        KLog.e("54");
        htmlInterface.takePhoto(type, max, ownerObject, ownerType, ownerId, takePicCallback, offlineIsUploadImage);
    }

    /**
     * 拍照功能
     *
     * @param type                 拍照后上传图片的方式
     * @param max                  拍照的最大数量
     * @param ownerObject          H5使用的参数
     * @param ownerType            图片的类型
     * @param ownerId              H5使用的参数
     * @param takePicCallback      拍照函数回调
     * @param offlineIsUploadImage 离线状态是否需要上传图片
     * @param takePhotoOkCallback  拍照成功后是否需要先通知H5
     */

    @JavascriptInterface
    public void takePhoto(String type, String max, String ownerObject, String ownerType, String ownerId, String takePicCallback, String offlineIsUploadImage, String takePhotoOkCallback) {
        KLog.e("73");
        htmlInterface.takePhoto(type, max, ownerObject, ownerType, ownerId, takePicCallback, offlineIsUploadImage, takePhotoOkCallback);
    }

    /**
     * 拍照功能
     *
     * @param type                 拍照后上传图片的方式
     * @param max                  拍照的最大数量
     * @param ownerObject          H5使用的参数
     * @param ownerType            图片的类型
     * @param ownerId              H5使用的参数
     * @param takePicCallback      拍照函数回调
     * @param offlineIsUploadImage 离线状态是否需要上传图片
     * @param takePhotoOkCallback  拍照成功后是否需要先通知H5
     * @param openAlbum            是否打开相册 0是不打开，1是打开
     */

    @JavascriptInterface
    public void takePhoto(String type, String max, String ownerObject, String ownerType, String ownerId, String takePicCallback, String offlineIsUploadImage, String takePhotoOkCallback, String openAlbum) {
       KLog.e("90");
        htmlInterface.takePhoto(type, max, ownerObject, ownerType, ownerId, takePicCallback, offlineIsUploadImage, takePhotoOkCallback, openAlbum);
    }

    /**
     * 拍照功能
     *
     * @param type                 拍照后上传图片的方式
     * @param max                  拍照的最大数量
     * @param ownerObject          H5使用的参数
     * @param ownerType            图片的类型
     * @param ownerId              H5使用的参数
     * @param takePicCallback      拍照函数回调
     * @param offlineIsUploadImage 离线状态是否需要上传图片
     * @param takePhotoOkCallback  拍照成功后是否需要先通知H5
     * @param openAlbum            是否打开相册 0是不打开，1是打开
     * @param recordVideoCallback  小视频录制回调
     * @param openRecordVideo      是否显示小视频录制选择框
     * @param openVideoAlbum       是否允许选择相册里的小视频
     */

    @JavascriptInterface
    public void takePhoto(String type, String max, String ownerObject, String ownerType, String ownerId, String takePicCallback, String offlineIsUploadImage, String takePhotoOkCallback, String openAlbum, String recordVideoCallback, String openRecordVideo, String openVideoAlbum) {
        KLog.e("113");
        htmlInterface.takePhoto(type, max, ownerObject, ownerType, ownerId, takePicCallback, offlineIsUploadImage, takePhotoOkCallback, openAlbum, recordVideoCallback, openRecordVideo, openVideoAlbum);
    }


    @JavascriptInterface
    public void takePhoto(String type, String max, String ownerObject, String ownerType, String ownerId, String takePicCallback, String offlineIsUploadImage, String takePhotoOkCallback, String openAlbum, String recordVideoCallback, String openRecordVideo, String openVideoAlbum, String uploadedCount) {
        KLog.e("120");
        htmlInterface.takePhoto(type, max, ownerObject, ownerType, ownerId, takePicCallback, offlineIsUploadImage, takePhotoOkCallback, openAlbum, recordVideoCallback, openRecordVideo, openVideoAlbum, uploadedCount);
    }

    /**
     * 扫码
     *
     * @param scanCallback 扫码函数回调
     */
    @JavascriptInterface
    public void openScan(String scanCallback) {
        htmlInterface.openScan(scanCallback);
    }


    @JavascriptInterface
    public void getInspOfflineTaskStatus(String call) {
        htmlInterface.getInspOfflineTaskStatus(call);
    }

    @JavascriptInterface
    public void getInspOffineUploadTask() {
        KLog.e("getInspOffineUploadTask");
        htmlInterface.getInspOffineUploadTask();
    }



    /**
     * 跳转到首页
     */
    @JavascriptInterface
    public void gotoIndex() {
        htmlInterface.gotoIndex();
    }

    /**
     * 跳转到登录
     */
    @JavascriptInterface
    public void gotoLogin() {
        htmlInterface.gotoLogin();
    }

    /**
     * 获取token
     *
     * @param getAccessTokenCallback 获取token函数回调
     */
    @JavascriptInterface
    public void getAccessToken(String getAccessTokenCallback) {
        htmlInterface.getAccessToken(getAccessTokenCallback);
    }

    /**
     * 拨打电话
     *
     * @param phone 电话号码
     */
    @JavascriptInterface
    public void callPhone(String phone) {
        htmlInterface.callPhone(phone);
    }


    /**
     * 返回
     */
    @JavascriptInterface
    public void back() {
        htmlInterface.back();
    }

    /**
     * 下载
     *
     * @param downloadName 文件名称
     * @param downloadUrl  下载路径
     * @param downloadByte 文件大小
     */
    @JavascriptInterface
    public void downloadFile(String downloadName, String downloadUrl, String downloadByte) {
        htmlInterface.downloadFile(downloadName, downloadUrl, downloadByte);
    }

    /**
     * 删除离线图片
     *
     * @param id 图片ID
     */
    @JavascriptInterface
    public void delPhoto(String id) {
        htmlInterface.delPhoto(id);
    }

    /**
     * 离线保存H5传过来的图片
     *
     * @param ownerObject
     * @param ownerId
     * @param ownerType
     * @param base64      base64图片
     */
    @JavascriptInterface
    public void getBasePicture(String ownerObject, String ownerId, String ownerType, String base64) {
        htmlInterface.getBasePicture(ownerObject, ownerId, ownerType, base64);
    }

    /**
     * 离线数据未上传标识
     */
    @JavascriptInterface
    public void uploadedOfflineData(String judge) {
        htmlInterface.uploadedOfflineData(judge);
    }


    /**
     * 获取本地当前语言
     *
     * @param currentLanguageCallback 回调函数名称
     */
    @JavascriptInterface
    public void getNativeCurrentLanguage(String currentLanguageCallback) {
        htmlInterface.getNativeCurrentLanguage(currentLanguageCallback);
    }

    /**
     * 获取当前网络状态
     */
    @JavascriptInterface
    public void getWorkStatus() {
        htmlInterface.getWorkStatus();
    }

    /**
     * 调用webview刷新界面
     */
    @JavascriptInterface
    public void reloadWebview() {
        htmlInterface.reloadWebview();
    }

    /**
     * 打开设置个人信息界面
     */
    @JavascriptInterface
    public void openPresionInfoActivity() {
        htmlInterface.openPresionInfoActivity();
    }

    /**
     * 获取经纬度
     */
    @JavascriptInterface
    public void getLongAndLat(String gpsCallback) {
        htmlInterface.getLongAndLat(gpsCallback);
    }


    /**
     * 获取实时获取到经纬度
     */
    @JavascriptInterface
    public void getCurrentTimeLongAndLat(String gpsCallback) {
        htmlInterface.getCurrentTimeLongAndLat(gpsCallback);
    }

    /**
     * 设置桌面角标数
     *
     * @param number
     */
    @JavascriptInterface
    public void setBadgeNumber(int number) {
        htmlInterface.setBadgeNumber(number);
    }


    /**
     * 设置当前是离线还是在线模式
     * networkMode 0代表在线模式，1代表离线模式
     */
    @JavascriptInterface
    public void setNetworkMode(String networkMode) {
        htmlInterface.setNetworkMode(networkMode);
    }

    /**
     * 判断H5时候初始化是否成功
     */
    @JavascriptInterface
    public void initCallback(String result) {
        htmlInterface.initCallback(result);
    }

    /**
     * 打开NFC
     */
    @JavascriptInterface
    public void openNfc(String scanCallback) {
        htmlInterface.openNfc(scanCallback);
    }

    /**
     * 打开流媒体播放界面
     */
    @JavascriptInterface
    public void openRtmpVideoActivity(String rtmpId, String rtmpName, String rtmpType, String rtmpAddress, String rtmpStatus, String rtmpUrl) {
        htmlInterface.openRtmpVideoActivity(rtmpId, rtmpName, rtmpType, rtmpAddress, rtmpStatus, rtmpUrl);
    }

    /**
     * 打开小视频播放器
     */
    @JavascriptInterface
    public void openSmallVideo(String url) {
        htmlInterface.openSmallVideo(url);
    }

    /**
     * 打开小视频播放器
     */
    @JavascriptInterface
    public void setAvatarAuth(String isShowAvatar) {
        htmlInterface.setAvatarAuth(isShowAvatar);
    }

    /**
     * 打开小视频播放器
     */
    @JavascriptInterface
    public void getWifiStatus(String wifiCallback) {
        htmlInterface.getWifiStatus(wifiCallback);
    }

    /**
     * 是否需要显示首页返回箭头
     */
    @JavascriptInterface
    public void isShowHomeBack(String isShowHomeBackCallback) {
        htmlInterface.isShowHomeBack(isShowHomeBackCallback);
    }


    /**
     * 外部浏览器打开
     */
    @JavascriptInterface
    public void openExternalBrowser(String url) {
        htmlInterface.openExternalBrowser(url);
    }

    /**
     * 分享
     */

    @JavascriptInterface
    public void openShare(String url) {
        htmlInterface.openShare(url);
    }

    /**
     * 分享
     */

    @JavascriptInterface
    public void openShare(String title, String url) {
        htmlInterface.openShare(title, url);
    }

    /**
     * 分享
     */

    @JavascriptInterface
    public void openShareAddTitle(String title, String url) {
        htmlInterface.openShareAddTitle(title, url);
    }

    @JavascriptInterface
    public void getStatusBar(String callBack) {
        htmlInterface.getStatusBar(callBack);
    }

    @JavascriptInterface
    public void changStatusBarColor(int color) {
        htmlInterface.changStatusBarColor(color);
    }

    //获取没有上传的文件工单号，以及工单号对应未上传的文件数目
    @JavascriptInterface
    public void getNoUploadFileNum(String callback1) {
        htmlInterface.getNoUploadFileNum(callback1);
    }


    //开始上传文件 callback2 为上传成功之后给h5一个 工单号
    @JavascriptInterface
    public void startUploadFile(String callback2) {
        htmlInterface.startUploadFile(callback2);
    }

    @JavascriptInterface
    public void startBatchUploadFile() {
        htmlInterface.startBatchUploadFile("");
        //Log.e("1111", "startBatchUploadFile");
    }

    @JavascriptInterface
    public void showNativeInspectionDetial(String str){
        htmlInterface.showNativeInspectionDetial(str);
    }

    @JavascriptInterface
    public void downLoadInspection(String json){
        htmlInterface.downLoadInspection(json);
    }

    @JavascriptInterface
    public void backNativeLastPage(){
        htmlInterface.backNativeLastPage();
    }

    @JavascriptInterface
    public void reportOrderSuccess(String json){
        htmlInterface.reportOrderSuccess(json);
    }

    @JavascriptInterface
    public void reportRequirementSuccess(String json){
        htmlInterface.reportOrderSuccess(json);
    }

    @JavascriptInterface
    public void changeInspectionState(String json){
        Log.e("huohuohuohuohuo",json);
        htmlInterface.changeInspectionState(json);
    }

    @JavascriptInterface
    public void getNativeFileData(String id){
        htmlInterface.getNativeFileData(id);
    }

    /**
     * /**
     * H5交互回调接口
     */
    public interface HtmlInterface {

        void takePhoto(String type, String max, String ownerObject, String ownerType, String ownerId, String takePicCallback);

        void takePhoto(String type, String max, String ownerObject, String ownerType, String ownerId, String takePicCallback, String offlineIsUploadImage);

        void takePhoto(String type, String max, String ownerObject, String ownerType, String ownerId, String takePicCallback, String offlineIsUploadImage, String takePhotoOkCallback);

        void takePhoto(String type, String max, String ownerObject, String ownerType, String ownerId, String takePicCallback, String offlineIsUploadImage, String takePhotoOkCallback, String openAlbum);

        void takePhoto(String type, String max, String ownerObject, String ownerType, String ownerId, String takePicCallback, String offlineIsUploadImage, String takePhotoOkCallback, String openAlbum, String recordVideoCallback, String openRecordVideo, String openVideoAlbum);

        void takePhoto(String type, String max, String ownerObject, String ownerType, String ownerId, String takePicCallback, String offlineIsUploadImage, String takePhotoOkCallback, String openAlbum, String recordVideoCallback, String openRecordVideo, String openVideoAlbum, String uploadedCount);

        void openScan(String scanCallback);

        void openSmallVideo(String url);

        void setAvatarAuth(String isShowAvatar);

        void back();

        void gotoLogin();

        void gotoIndex();

        void getAccessToken(String getAccessTokenCallback);

        void callPhone(String phone);

        void downloadFile(String downloadName, String downloadUrl, String downloadByte);

        void delPhoto(String id);

        void getBasePicture(String ownerObject, String ownerId, String ownerType, String base64);

        void uploadedOfflineData(String judge);

        void saveH5DebugLog(String level, String logs);

        void getNativeCurrentLanguage(String currentLanguageCallback);

        void saveH5DataToLocal(String dataName, String dataValue, String saveH5DataToLocalCallBack);

        void deleteH5DataForLocal(String dataName);

        void getH5DataForLocal(String dataName, String uuid, String getH5DataForLocalCallback);

        void getWorkStatus();

        void reloadWebview();

        void openPresionInfoActivity();

        void getLongAndLat(String gpsCallback);

        void getCurrentTimeLongAndLat(String gpsCallback);

        void setBadgeNumber(int number);

        void setNetworkMode(String networkMode);

        void initCallback(String result);

        void openNfc(String scanCallback);

        void getWifiStatus(String wifiCallback);

        void openRtmpVideoActivity(String rtmpId, String rtmpName, String rtmpType, String rtmpAddress, String rtmpStatus, String rtmpUrl);

        void isShowHomeBack(String isShowHomeBackCallback);

        void openExternalBrowser(String url);

        void openShare(String url);

        void openShare(String title, String url);

        void openShareAddTitle(String title, String url);

        void getStatusBar(String callBack);

        void changStatusBarColor(int color);

        void getNoUploadFileNum(String callback1);

        void startUploadFile(String callback2);

        void startBatchUploadFile(String callback2);

        void showNativeInspectionDetial(String str);

        void downLoadInspection(String json);

        void backNativeLastPage();

        void reportOrderSuccess(String json);

        void getInspOfflineTaskStatus(String call);
        void getInspOffineUploadTask();

        void changeInspectionState(String json);

        void  getNativeFileData(String id);
    }


}
